package com.zrwl.poscloud.base;

import com.zrwl.poscloud.base.entity.*;
import com.zrwl.poscloud.base.utils.GenerateCodeUtil;
import org.junit.Test;

import java.io.File;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘思童
 * @create 2021/1/25 19:39
 **/
public class GenerateCode {

    static String projectName = "pos_psms";//项目名称（项目路径名称）
    static String author = "刘思童";//作者
    static String defaultClassUrl = "/src/main/java";//默认java源码路径
    static String defaultResourceUrl = "/src/main/resources";//默认resources源码路径

    static String servicePath = "/s03_xo";//子模块相对路径（相对项目的子路径）
    static String servicePackage = "com.zrwl.poscloud.xo.service";
    static String serviceEnd = "Service";
    static String serviceImplEnd = "ServiceImpl";

    static String voPath = "/s03_xo";
    static String voPackage = "com.zrwl.poscloud.xo.vo";
    static String voEnd = "VO";

    static String mapperPath = "/s03_xo";
    static String mapperPackage = "com.zrwl.poscloud.xo.mapper";
    static String mapperEnd = "Mapper";
    static String viewPath = "/vue_admin";
    // static String viewPackage = "src.views.baseInfo";
//     static String viewPackage = "src.views.system";
//     static String viewPackage = "src.view.systemConfig";
//    static String viewPackage = "src.view.business.payableManage";
//    static String viewPackage = "src.view.company.contractManage";
//    static String viewPackage = "src.view.company.watchManage";
    static String viewPackage = "src.view.log.withholdLog";
//    static String viewPackage = "src.view.company";
    //static String viewPackage = "src.views.tradeInfo";
    // static String viewPackage = "src.views.message";
    static String controllerPath = "/s04_core";
//    static String controllerPackage = "com.zrwl.poscloud.admin.restapi.tradeInfo";
      static String controllerPackage = "com.zrwl.poscloud.core.restapi.admin.baseInfo";
    //static String controllerPackage = "com.zrwl.poscloud.admin.restapi.tradeInfo";
    //  static String controllerPackage = "com.zrwl.poscloud.admin.restapi.others";
    static String controllerEnd = "RestApi";
    static boolean overWrite = true;
    /**
     * 基础管理 baseInfo
     */
//    static String entitySummary = "消费场所"; static HouseRecord entity = new HouseRecord();
//    static String entitySummary = "POS机"; static Pos entity = new Pos();
//    static String entitySummary = "商户机构"; static Dept entity = new Dept();
//    static String entitySummary = "消费人员"; static Employee entity = new Employee();
//    static String entitySummary = "IC消费卡"; static ICCard entity = new ICCard();
//    static String entitySummary = "用户信息"; static User entity = new User();
//    static String entitySummary = "用户关注消费人员"; static UserEmployeeR entity = new UserEmployeeR();
//    static String entitySummary = "商户管理员"; static CompanyAdminR entity = new CompanyAdminR();
    static String entitySummary = "管理员教师关联";
    static TeacherAdminR entity = new TeacherAdminR();

    /**
     * 交易业务 tradeInfo
     */
//    static String entitySummary = "账簿"; static Account entity = new Account();
//    static String entitySummary = "账单"; static AccountDetail entity = new AccountDetail();
//    static String entitySummary = "支付账单关联"; static AccountDetailPayR entity = new AccountDetailPayR();
//    static String entitySummary = "订单"; static AccountOrder entity = new AccountOrder();
//    static String entitySummary = "订单账单关联"; static AccountDetailOrderR entity = new AccountDetailOrderR();
//    static String entitySummary = "支付"; static AccountPay entity = new AccountPay();
//    static String entitySummary = "账户变动"; static IccardLog entity = new IccardLog();
//    static String entitySummary = "刷卡记录"; static IccardRecord entity = new IccardRecord();
//    static String entitySummary = "在线支付"; static PayOnlineRecord entity = new PayOnlineRecord();
//    static String entitySummary = "标签类型"; static LabelType entity = new LabelType();
//    static String entitySummary = "标签数据"; static LabelData entity = new LabelData();
//    static String entitySummary = "商户业务会计科目配置"; static CompanyBusinessName entity = new CompanyBusinessName();

//    static String entitySummary = "人员门禁"; static AccessControlEmployeeR entity = new AccessControlEmployeeR();

    public static void main(String[] args) {
        String thisPath = GenerateCode.class.getClassLoader().getResource("").getPath();
        thisPath = thisPath.substring(1, thisPath.indexOf(projectName) + projectName.length());
        prl("当前类的路径：" + thisPath);
        /***
         * 1. 生成vo
         * 2. 生成mapper
         * 3. 生成service
         * 4. 生成controller
         * 5. 生成view和路由
         */

        //1. 生成vo
        generateVo(thisPath);
        //2. 生成mapper
        generateMapper(thisPath);
//        3. 生成service
        generateService(thisPath);
//        4. 生成controller
        generateController(thisPath);
//        5. 生成view和路由
 /*       generateView(thisPath);*/
    }

    static void generateView(String thisPath) {
        String entityName = entity.getClass().getSimpleName();
        entityName = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
        viewPath = thisPath + viewPath + "/" + viewPackage.replaceAll("\\.", "/");
        prl(viewPath);
        GenerateCodeUtil.createDir(viewPath);
        String viewName = entityName;
        File viewFile = GenerateCodeUtil.createFile(viewPath, viewName + ".vue", overWrite);
        prl(viewName);
        Map<Class, Boolean> viewImportMap = new HashMap();
        try {
            GenerateCodeUtil.write(viewFile, "" +
                    "<template>\n" +
                    "  <div class=\"app-container\" style=\"height: 100%\">\n" +
                    " <div :style=\"{width:'100%',float: 'left',  height: '100%',display:'flex',flexFlow: 'column'}\"  class=\"tt\">"+
                    "    <!-- 查询和其他操作 -->\n" +
                    "    <div class=\"filter-container\" style=\"margin: 0px 0 10px 0;\">\n" +
                    "      <el-input\n" +
                    "        @keyup.enter.native=\"handleFind\"\n" +
                    "        class=\"filter-item\"\n" +
                    "        clearable\n" +
                    "        placeholder=\"请输入名称\"\n" +
                    "        style=\"width: 200px;\"\n" +
                    "        v-model=\"keyword\"\n" +
                    "      ></el-input>\n" +
                    "\n" +
                    "      <el-button @click=\"handleFind\" class=\"filter-item\" icon=\"el-icon-search\" type=\"primary\">查找\n" +
                    "      </el-button>\n" +
                    "\n" +
                    "      <el-button class=\"filter-item\" type=\"primary\" @click=\"handleAdd\" icon=\"el-icon-plus\" plain>\n" +
                    "        添加\n" +
                    "      </el-button>\n" +
                    "    </div>\n" +
                    "\n" +
                    "     <div ref=\"tableContainer\" style=\"flex:1;height: 0px;\">" +
                    "    <el-table :data=\"tableData\" style=\"width: 100%\" height=\"100%\">\n" +
                    "\n" +
                    "      <el-table-column align=\"center\" label=\"名称\" width=\"150\">\n" +
                    "        <template slot-scope=\"scope\">\n" +
                    "          <span>{{ scope.row.name }}</span>\n" +
                    "        </template>\n" +
                    "      </el-table-column>\n" +
                    "\n" +

                    "\n <!-- 字典的应用示例" +
                    "      <el-table-column align=\"center\" label=\"类型\" width=\"120\">\n" +
                    "        <template slot-scope=\"scope\">\n" +
                    "          <el-tag :type=\"item.listClass\" :key=\"index\" v-for=\"(item,index) in typeDictList\"\n" +
                    "                  v-if=\"scope.row.type == item.dictValue\">\n" +
                    "            {{ item.dictLabel }}\n" +
                    "          </el-tag>\n" +
                    "        </template>\n" +
                    "      </el-table-column>\n" +
                    " 后续添加其他列 -->\n" +

                    "\n" +
                    "      <el-table-column align=\"center\" label=\"更新时间\" width=\"160\">\n" +
                    "        <template slot-scope=\"scope\">\n" +
                    "          <span>{{ scope.row.updateTime }}</span>\n" +
                    "        </template>\n" +
                    "      </el-table-column>\n" +
                    "      <el-table-column label=\"状态\" width=\"100\">\n" +
                    "        <template slot-scope=\"scope\">\n" +
                    "          <el-tag :type=\"item.listClass\" :key=\"index\" v-for=\"(item,index) in statusList\"\n" +
                    "                  v-if=\"scope.row.status == item.dictValue\">\n" +
                    "            {{ item.dictLabel }}\n" +
                    "          </el-tag>\n" +
                    "        </template>\n" +
                    "      </el-table-column>\n" +
                    "\n" +
                    "      <el-table-column label=\"操作\" min-width=\"140\" fixed=\"right\">\n" +
                    "        <template slot-scope=\"scope\">\n" +
                    "          <el-button @click=\"handleEdit(scope.row)\" size=\"mini\" type=\"primary\" plain>编辑\n" +
                    "          </el-button>\n" +
                    "          <el-popconfirm\n" +
                    "            icon=\"el-icon-info\"\n" +
                    "            icon-color=\"red\"\n" +
                    "            @confirm=\"handleDelete(scope.row)\"\n" +
                    "            :title=\"'确定需要删除【'+scope.row.name+'】？'\">\n" +
                    "            <el-button slot=\"reference\" size=\"mini\" type=\"danger\" plain>删除\n" +
                    "            </el-button>\n" +
                    "          </el-popconfirm>\n " +
                    "        </template>\n" +
                    "      </el-table-column>\n" +
                    "    </el-table>\n" +
                    "    </div>\n" +
                    "    <!--分页-->\n" +
                    "    <div class=\"block\">\n" +
                    "      <el-pagination\n" +
                    "        :current-page.sync=\"currentPage\"\n" +
                    "        :page-sizes=\"[10, 20, 50, 100, 200, 500]\"" +
                    "        :page-size=\"pageSize\"\n" +
                    "        :total=\"total\"\n" +
                    "        @size-change=\"handleSizeChange\"" +
                    "        @current-change=\"handleCurrentChange\"\n" +
                    "        layout=\"total, sizes, prev, pager, next, jumper\"\n" +
                    "      ></el-pagination>\n" +
                    "    </div>\n" +
                    "  </div>\n" +
                    "    <!--编辑对话框-->\n" +
                    "\n" +
                    "    <el-dialog v-bind=\"$attrs\" v-on=\"$listeners\" @open=\"onOpen\" @close=\"onClose\" :title=\"title\"\n" +
                    "               :modal-append-to-body=\"false\" class=\"abow_dialog\"\n" +
                    "               :visible.sync=\"dialogFormVisible\">\n" +
                    "      <el-form ref=\"elForm\" :model=\"formData\" :rules=\"rules\" size=\"medium\" label-width=\"100px\">\n" +
                    "\n" +
                    "        <el-col :span=\"16\">\n" +
                    "          <el-form-item label=\"名称\" :label-width=\"formLabelWidth\" prop=\"name\">\n" +
                    "            <el-input v-model=\"formData.name\" placeholder=\"请输入名称\" :maxlength=\"30\" show-word-limit\n" +
                    "                      clearable :style=\"{width: '100%'}\"></el-input>\n" +
                    "          </el-form-item>\n" +
                    "        </el-col>\n" +
                    "  <!--编辑对话框     " +
                    "       <el-col :span=\"8\">\n" +
                    "          <el-form-item label=\"类型\" :label-width=\"formLabelWidth\" prop=\"type\">\n" +
                    "            <el-select v-model=\"formData.type\" placeholder=\"请选择\" style=\"width:100%\">\n" +
                    "              <el-option\n" +
                    "                v-for=\"item in typeDictList\"\n" +
                    "                :key=\"item.uid\"\n" +
                    "                :label=\"item.dictLabel\"\n" +
                    "                :value=\"parseInt(item.dictValue)\"\n" +
                    "              ></el-option>\n" +
                    "            </el-select>\n" +
                    "          </el-form-item>\n" +
                    "        </el-col>" +
                    "   下拉框示例 -->  \n" +

                    "        <el-col :span=\"8\">\n" +
                    "          <el-form-item label=\"状态\" :label-width=\"formLabelWidth\" prop=\"status\">\n" +
                    "            <el-select v-model=\"formData.status\" placeholder=\"请选择\" style=\"width:100%\">\n" +
                    "              <el-option\n" +
                    "                v-for=\"item in statusList\"\n" +
                    "                :key=\"item.uid\"\n" +
                    "                :label=\"item.dictLabel\"\n" +
                    "                :value=\"parseInt(item.dictValue)\"\n" +
                    "              ></el-option>\n" +
                    "            </el-select>\n" +
                    "          </el-form-item>\n" +
                    "        </el-col>\n" +

                    "      </el-form>\n" +
                    "      <div slot=\"footer\">\n" +
                    "        <el-button @click=\"cancelForm\">取 消</el-button>\n" +
                    "        <el-button @click=\"submitForm\" type=\"primary\">确 定</el-button>\n" +
                    "      </div>\n" +
                    "    </el-dialog>\n" +
                    "\n" +
                    "  </div>\n" +
                    "</template>\n" +
                    "\n" +
                    "<script>\n" +
                    "  import {add, edit,del, getList} from \"@/api/" + entityName + "\";\n" +
                    "  import {getListByDictTypeList} from \"@/api/system/sysDictData\"\n" +
                    "\n" +
                    "  export default {\n" +
                    "    name: \"V" + entitySummary + "管理\",\n" +
                    "    data() {\n" +
                    "      return {\n" +
                    "        tableData: [],\n" +
                    "        keyword: \"\",\n" +
                    "        currentPage: 1,\n" +
                    "        pageSize: 10,\n" +
                    "        total: 0, //总数量\n" +
                    "        title: \"\",\n" +
                    "        dialogFormVisible: false, //控制弹出框\n" +
                    "        formLabelWidth: \"120px\",\n" +
                    "        isEditForm: false,\n" +
                    "        editRow: null,\n" +
                    "        typeDictList: [], //类型\n" +
                    "        statusList: [{\n" +
                    "          uid: \"state1\",\n" +
                    "          listClass: \"success\",\n" +
                    "          dictValue: 1,\n" +
                    "          dictLabel: \"正常\"\n" +
                    "        }, {\n" +
                    "          uid: \"state2\",\n" +
                    "          listClass: \"warning\",\n" +
                    "          dictValue: 2,\n" +
                    "          dictLabel: \"冻结\"\n" +
                    "        }, {\n" +
                    "          uid: \"state0\",\n" +
                    "          listClass: \"danger\",\n" +
                    "          dictValue: 0,\n" +
                    "          dictLabel: \"已删除\"\n" +
                    "        }],\n" +
                    "        formData: this.getFormObject(),\n" +
                    "        rules: {\n" +
                    "          name: [\n" +
                    "            {required: true, message: '名称不能为空', trigger: 'blur'},\n" +
                    "            {min: 1, max: 30, message: '长度在1到30个字符'},\n" +
                    "          ],\n" +
                    "        }\n" +
                    "      };\n" +
                    "    },\n" +
                    "    created() {\n" +
                    "      // 字典查询\n" +
                    "      this.getDictList();\n" +
                    "      //刷新上层节点的数据\n" +
                    "      //this.getParentList();\n" +
                    "      this.mainList();\n" +
                    "    },\n" +
                    "    activated(){\n" +
                    "      //传递过来参数\n" +
                    "      //this.formData.houseUid = this.$route.query.houseUid;\n" +
                    "      //刷新上层节点的数据\n" +
                    "      //this.getParentList();\n" +
                    "      this.mainList();\n" +
                    "    }," +
                    "    methods: {\n" +
                    "      mainList: function () {\n" +
                    "        var params = {};\n" +
                    "        params.keyword = this.keyword;\n" +
                    "        params.currentPage = this.currentPage;\n" +
                    "        params.pageSize = this.pageSize;\n" +
                    "        getList(params).then(response => {\n" +
                    "          if (response.code == this.$ECode.SUCCESS) {\n" +
                    "            this.tableData = response.data.records;\n" +
                    "            this.currentPage = response.data.current;\n" +
                    "            this.pageSize = response.data.size;\n" +
                    "            this.total = response.data.total;\n" +
                    "          }\n" +
                    "        });\n" +
                    "      },\n" +
                    "      onOpen() {\n" +
                    "      },\n" +
                    "      onClose() {\n" +
                    "      },\n" +
                    "      close() {\n" +
                    "      },\n" +
                    "      /**\n" +
                    "       * 字典查询\n" +
                    "       */\n" +
                    "      getDictList: function () {\n" +
                    "        var dictTypeList = ['com_type']\n" +
                    "        getListByDictTypeList(dictTypeList).then(response => {\n" +
                    "          if (response.code == this.$ECode.SUCCESS) {\n" +
                    "            var dictMap = response.data;\n" +
                    "            this.typeDictList = dictMap.com_type.list\n" +
                    "          }\n" +
                    "        });\n" +
                    "      },\n" +
                    "      /**\n" +
                    "       * 加载上级页面的数据，防止此页面依赖上级页面的数据而上级页面更改后此页面的数据不刷新的问题\n" +
                    "       */\n" +
                    "      getParentList:function () {\n" +
                    "      }," +
                    "      getFormObject: function () {\n" +
                    "        var formObject = {\n" +
                    "          uid: null,\n" +
                    "          status: 1,\n" +
                    "        };\n" +
                    "        return formObject;\n" +
                    "      },\n" +
                    "      handleFind: function () {\n" +
                    "        this.mainList();\n" +
                    "      },\n" +
                    "      handleAdd: function () {\n" +
                    "        this.title = \"增加" + entitySummary + "\";\n" +
                    "        this.dialogFormVisible = true;\n" +
                    "        this.formData = this.getFormObject();\n" +
                    "        this.isEditForm = false;\n" +
                    "      },\n" +
                    "      handleEdit: function (row) {\n" +
                    "        this.title = \"编辑" + entitySummary + "\";\n" +
                    "        this.dialogFormVisible = true;\n" +
                    "        this.isEditForm = true;\n" +
                    "        this.formData = row;\n" +
                    "        this.editRow = Object.assign({}, row);\n" +
                    "      },\n" +
                    "      handleDelete: function (row) {\n" +
                    "        var params = {};\n" +
                    "        params.uid = row.uid;\n" +
                    "        del(params).then(response => {\n" +
                    "          if (response.code == this.$ECode.SUCCESS) {\n" +
                    "            this.$commonUtil.message.success(response.message)\n" +
                    "            this.mainList();\n" +
                    "          } else {\n" +
                    "            this.$commonUtil.message.error(response.message)\n" +
                    "          }\n" +
                    "        });\n" +
                    "      },\n" +
                    "      handleSizeChange: function (val) {\n" +
                    "        this.pageSize = val;\n" +
                    "        this.currentPage = 1;\n" +
                    "        this.mainList();\n" +
                    "      },\n" +
                    "      handleCurrentChange: function (val) {\n" +
                    "        this.currentPage = val;\n" +
                    "        this.mainList();\n" +
                    "      },\n" +
                    "      cancelForm: function () {\n" +
                    "        this.dialogFormVisible = false\n" +
                    "        if (this.editRow != null) {\n" +
                    "          Object.assign(this.formData, this.editRow);\n" +
                    "          this.editRow = null;\n" +
                    "        }\n" +
                    "      },\n" +
                    "      submitForm: function () {\n" +
                    "        this.$refs.elForm.validate((valid) => {\n" +
                    "          if (!valid) {\n" +
                    "            console.log(\"校验出错\")\n" +
                    "          } else {\n" +
                    "            if (this.isEditForm) {\n" +
                    "              edit(this.formData).then(response => {\n" +
                    "                if (response.code == this.$ECode.SUCCESS) {\n" +
                    "                  this.$notify({\n" +
                    "                    title: \"成功\",\n" +
                    "                    message: response.message,\n" +
                    "                    type: \"success\"\n" +
                    "                  });\n" +
                    "                  this.dialogFormVisible = false\n" +
                    "                  this.mainList();\n" +
                    "                } else {\n" +
                    "                  this.$notify.error({\n" +
                    "                    title: \"失败\",\n" +
                    "                    message: response.message\n" +
                    "                  });\n" +
                    "                }\n" +
                    "              });\n" +
                    "            } else {\n" +
                    "              add(this.formData).then(response => {\n" +
                    "                if (response.code == this.$ECode.SUCCESS) {\n" +
                    "                  this.$notify({\n" +
                    "                    title: \"成功\",\n" +
                    "                    message: response.message,\n" +
                    "                    type: \"success\"\n" +
                    "                  });\n" +
                    "                  this.dialogFormVisible = false\n" +
                    "                  this.mainList();\n" +
                    "                } else {\n" +
                    "                  this.$notify.error({\n" +
                    "                    title: \"失败\",\n" +
                    "                    message: response.message\n" +
                    "                  });\n" +
                    "                }\n" +
                    "              });\n" +
                    "            }\n" +
                    "          }\n" +
                    "        })\n" +
                    "      }\n" +
                    "    }\n" +
                    "  };\n" +
                    "</script>\n" +
                    "<style lang=\"scss\" type=\"text/scss\" scoped>\n</style>");
            String router = "" +
                    "        path: '" + entityName + "',\n" +
                    "        name: 'V" + entitySummary + "管理',\n" +
                    "        component: () => import('@/view/" + viewPackage.substring(viewPackage.indexOf("view/") + 5) + "/" + entityName + "'),\n" +
                    "        meta: {title: '" + entitySummary + "管理', icon: 'user1'}" +
                    "";
            prl("---------------------vue 路由---------------------");
            prl(router);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void generateController(String thisPath) {
        String entityName = entity.getClass().getSimpleName();
        String entityBean = entityName.substring(0, 1).toLowerCase() + entityName.substring(1);
        String voName = entityName + voEnd;
        String voParam = voName.substring(0, 1).toLowerCase() + voName.substring(1);
        String serviceName = entityName + serviceEnd;
        String serviceBeanName = serviceName.substring(0, 1).toLowerCase() + serviceName.substring(1);
        controllerPath = thisPath + controllerPath + defaultClassUrl + "/" + controllerPackage.replaceAll("\\.", "/");
        System.out.println(controllerPath);
        prl(controllerPath);
        GenerateCodeUtil.createDir(controllerPath);
        String controllerName = entityName + controllerEnd;
        File controllerFile = GenerateCodeUtil.createFile(controllerPath, controllerName + ".java", overWrite);
        prl(controllerName);
        Map<Class, Boolean> controllerImportMap = new HashMap();
        try {
            GenerateCodeUtil.write(controllerFile, "package " + controllerPackage + ";");
            GenerateCodeUtil.write(controllerFile, "" +
                    "import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;\n" +
                    "import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;\n" +
                    "import com.zrwl.poscloud.commons.exception.ThrowableUtils;\n" +
                    "import com.zrwl.poscloud.commons.utils.ResultUtil;\n" +
                    "import com.zrwl.poscloud.commons.validator.group.Delete;\n" +
                    "import com.zrwl.poscloud.commons.validator.group.GetList;\n" +
                    "import com.zrwl.poscloud.commons.validator.group.Insert;\n" +
                    "import com.zrwl.poscloud.commons.validator.group.Update;\n" +
                    "import io.swagger.annotations.Api;\n" +
                    "import io.swagger.annotations.ApiOperation;\n" +
                    "import lombok.extern.slf4j.Slf4j;\n" +
                    "import org.springframework.beans.factory.annotation.Autowired;\n" +
                    "import org.springframework.validation.BindingResult;\n" +
                    "import org.springframework.validation.annotation.Validated;\n" +
                    "import org.springframework.web.bind.annotation.PostMapping;\n" +
                    "import org.springframework.web.bind.annotation.RequestBody;\n" +
                    "import org.springframework.web.bind.annotation.RequestMapping;\n" +
                    "import org.springframework.web.bind.annotation.RestController;\n" +
                    "");
            GenerateCodeUtil.write(controllerFile, "import " + servicePackage + "." + entityName + serviceEnd + ";");
            GenerateCodeUtil.write(controllerFile, "import " + voPackage + "." + voName + ";");
            String classBg = "/**\n" +
                    " * " + entitySummary + " controller api类\n" +
                    " *\n" +
                    " * @author " + author + " AutoGenerate\n" +
                    " * @date " + now() + "\n" +
                    " */\n" +
                    "@RestController\n" +
                    "@Api(value = \"" + entitySummary + "相关接口\", tags = {\"" + entitySummary + "相关接口\"})\n" +
                    "@RequestMapping(\"/" + entityBean + "\")\n" +
                    "@Slf4j\n" +
                    "public class " + controllerName + " {\n" +
                    "    @Autowired\n" +
                    "    private " + serviceName + " " + serviceBeanName + ";" +
                    "" +
                    "";
            String classEd = "}";
            GenerateCodeUtil.write(controllerFile, classBg);
            String getPageList = "" +
                    "    @AuthorityVerify\n" +
                    "    @ApiOperation(value = \"获取" + entitySummary + "列表\", notes = \"获取" + entitySummary + "列表\", response = String.class)\n" +
                    "    @PostMapping(\"/getList\")\n" +
                    "    public String getList(@Validated({GetList.class}) @RequestBody " + voName + " " + voParam + ", BindingResult result) {\n" +
                    "        ThrowableUtils.checkParamArgument(result);\n" +
                    "        log.info(\"获取" + entitySummary + "列表: {}\", " + voParam + ");\n" +
                    "        return ResultUtil.successWithData(" + serviceBeanName + ".getPageList(" + voParam + "));\n" +
                    "    }\n";
            String getAllList = "" +
                    "    @AuthorityVerify\n" +
                    "    @ApiOperation(value = \"获取" + entitySummary + "列表\", notes = \"获取" + entitySummary + "列表\", response = String.class)\n" +
                    "    @PostMapping(\"/getAllList\")\n" +
                    "    public String getAllList(@Validated({GetList.class}) @RequestBody " + voName + " " + voParam + ", BindingResult result) {\n" +
                    "        ThrowableUtils.checkParamArgument(result);\n" +
                    "        log.info(\"获取" + entitySummary + "列表: {}\", " + voParam + ");\n" +
                    "        return ResultUtil.successWithData(" + serviceBeanName + ".getAllList(" + voParam + "));\n" +
                    "    }\n";
            String add = "" +
                    "    @AuthorityVerify\n" +
                    "    @OperationLogger(value = \"新增" + entitySummary + "\")" +
                    "    @ApiOperation(value = \"新增" + entitySummary + "\", notes = \"新增" + entitySummary + "\", response = String.class)\n" +
                    "    @PostMapping(\"/add\")\n" +
                    "    public String add(@Validated({Insert.class}) @RequestBody " + voName + " " + voParam + ", BindingResult result) {\n" +
                    "        ThrowableUtils.checkParamArgument(result);\n" +
                    "        log.info(\"新增" + entitySummary + ": {}\", " + voParam + ");\n" +
                    "        return " + serviceBeanName + ".add(" + voParam + ");\n" +
                    "    }\n";
            String edit = "" +
                    "    @AuthorityVerify\n" +
                    "    @OperationLogger(value = \"修改" + entitySummary + "\")" +
                    "    @ApiOperation(value = \"修改" + entitySummary + "\", notes = \"修改" + entitySummary + "\", response = String.class)\n" +
                    "    @PostMapping(\"/edit\")\n" +
                    "    public String edit(@Validated({Update.class}) @RequestBody " + voName + " " + voParam + ", BindingResult result) {\n" +
                    "        ThrowableUtils.checkParamArgument(result);\n" +
                    "        log.info(\"修改" + entitySummary + ": {}\", " + voParam + ");\n" +
                    "        return " + serviceBeanName + ".edit(" + voParam + ");\n" +
                    "    }\n";
            String delete = "" +
                    "    @AuthorityVerify\n" +
                    "    @OperationLogger(value = \"删除" + entitySummary + "\")" +
                    "    @ApiOperation(value = \"删除" + entitySummary + "\", notes = \"删除" + entitySummary + "\", response = String.class)\n" +
                    "    @PostMapping(\"/delete\")\n" +
                    "    public String delete(@Validated({Delete.class}) @RequestBody " + voName + " " + voParam + ", BindingResult result) {\n" +
                    "        ThrowableUtils.checkParamArgument(result);\n" +
                    "        log.info(\"删除" + entitySummary + ": {}\", " + voParam + ");\n" +
                    "        return " + serviceBeanName + ".delete(" + voParam + ");\n" +
                    "    }\n";
            GenerateCodeUtil.write(controllerFile, getPageList);
            GenerateCodeUtil.write(controllerFile, getAllList);
            GenerateCodeUtil.write(controllerFile, add);
            GenerateCodeUtil.write(controllerFile, edit);
            GenerateCodeUtil.write(controllerFile, delete);
            GenerateCodeUtil.write(controllerFile, classEd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void generateVo(String thisPath) {
        voPath = thisPath + voPath + defaultClassUrl + "/" + voPackage.replaceAll("\\.", "/");
        prl(voPath);
        GenerateCodeUtil.createDir(voPath);
        String entityName = entity.getClass().getSimpleName();
        String voName = entityName + voEnd;
        File voFile = GenerateCodeUtil.createFile(voPath, voName + ".java", overWrite);
        prl(voName);
        Map<Class, Boolean> voImportMap = new HashMap();
        try {
            GenerateCodeUtil.write(voFile, "package " + voPackage + ";");
            GenerateCodeUtil.write(voFile, "import com.zrwl.poscloud.commons.vo.BaseVO;\n" +
                    "import lombok.Data;");
            String classBg = "/**\n" +
                    " * " + entitySummary + " VO类\n" +
                    " *\n" +
                    " * @author " + author + " AutoGenerate\n" +
                    " * @date " + now() + "\n" +
                    " */\n" +
                    "@Data\n" +
                    "public class " + voName + " extends BaseVO<" + voName + "> {\n" +
                    "    private static final long serialVersionUID = 1L;";
            String classEd = "}";
            GenerateCodeUtil.write(voFile, classBg);

            Class cls = entity.getClass();
            Field[] fields = cls.getDeclaredFields();
            for (int i = 1; i < fields.length; i++) {
                Field f = fields[i];
                String type = f.getType().getSimpleName();
                if (type.equals("Date")) {
                    voImportMap.put(new Date().getClass(), true);
                    GenerateCodeUtil.write(voFile, "    @DateTimeFormat(pattern = \"yyyy-MM-dd HH:mm:ss\")\n" +
                            "    @JsonFormat(pattern = \"yyyy-MM-dd HH:mm:ss\")");
                    GenerateCodeUtil.doImport(voFile, "org.springframework.format.annotation.DateTimeFormat;");
                    GenerateCodeUtil.doImport(voFile, "com.fasterxml.jackson.annotation.JsonFormat;");
                }
                GenerateCodeUtil.write(voFile, "    private " + f.getType().getSimpleName() + " " + f.getName() + ";");

            }
            GenerateCodeUtil.write(voFile, classEd);
            for (Map.Entry<Class, Boolean> entry : voImportMap.entrySet()) {
                GenerateCodeUtil.doImport(voFile, entry.getKey().getName());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void generateMapper(String thisPath) {
        String entityName = entity.getClass().getSimpleName();
        mapperPath = thisPath + mapperPath + defaultClassUrl + "/" + mapperPackage.replaceAll("\\.", "/");
        prl(mapperPath);
        GenerateCodeUtil.createDir(mapperPath);
        String mapperName = entityName + mapperEnd;
        File mapperFile = GenerateCodeUtil.createFile(mapperPath, mapperName + ".java", overWrite);
        prl(mapperName);
        Map<Class, Boolean> mapperImportMap = new HashMap();
        try {
            GenerateCodeUtil.write(mapperFile, "package " + mapperPackage + ";");
            GenerateCodeUtil.write(mapperFile, "import com.zrwl.poscloud.base.superI.SuperMapper;");
            String classBg = "/**\n" +
                    " * " + entitySummary + " Mapper类\n" +
                    " *\n" +
                    " * @author " + author + " AutoGenerate\n" +
                    " * @date " + now() + "\n" +
                    " */\n" +
                    "public interface " + mapperName + " extends SuperMapper<" + entityName + "> {\n";
            String classEd = "}";
            GenerateCodeUtil.write(mapperFile, classBg);
            GenerateCodeUtil.write(mapperFile, classEd);
            GenerateCodeUtil.doImport(mapperFile, entity);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static void generateService(String thisPath) {
        String entityName = entity.getClass().getSimpleName();
        String voName = entityName + voEnd;
        String voParam = voName.substring(0, 1).toLowerCase() + voName.substring(1);
        servicePath = thisPath + servicePath + defaultClassUrl + "/" + servicePackage.replaceAll("\\.", "/");
        String serviceImplPath = servicePath + "/impl";
        prl(servicePath);
        prl(serviceImplPath);
        GenerateCodeUtil.createDir(servicePath);
        GenerateCodeUtil.createDir(serviceImplPath);
        String serviceName = entityName + serviceEnd;
        String serviceImplName = entityName + serviceImplEnd;
        String serviceBeanName = serviceName.substring(0, 1).toLowerCase() + serviceName.substring(1);
        File serviceFile = GenerateCodeUtil.createFile(servicePath, serviceName + ".java", overWrite);
        File serviceImplFile = GenerateCodeUtil.createFile(serviceImplPath, serviceImplName + ".java", overWrite);
        prl(serviceName);
        prl(serviceImplName);
        Map<Class, Boolean> serviceImportMap = new HashMap();
        try {
            GenerateCodeUtil.write(serviceFile, "package " + servicePackage + ";");
            GenerateCodeUtil.write(serviceFile, "import com.zrwl.poscloud.base.superI.SuperService;");
            GenerateCodeUtil.write(serviceFile, "import com.baomidou.mybatisplus.core.metadata.IPage;");
            GenerateCodeUtil.write(serviceFile, "import java.util.List;");

            GenerateCodeUtil.write(serviceFile, "import " + voPackage + "." + voName + ";");
            GenerateCodeUtil.doImport(serviceFile, entity);
            String classBg = "/**\n" +
                    " * " + entitySummary + " 服务类\n" +
                    " *\n" +
                    " * @author " + author + " AutoGenerate\n" +
                    " * @date " + now() + "\n" +
                    " */\n" +
                    "public interface " + serviceName + " extends SuperService<" + entityName + "> {\n";
            String classEd = "}";
            GenerateCodeUtil.write(serviceFile, classBg);
            String getPageList = "    public IPage<" + entityName + "> getPageList(" + voName + " " + voParam + ");";
            String getAllList = "    public List<" + entityName + "> getAllList(" + voName + " " + voParam + ");";
            String add = "    public String add(" + voName + " " + voParam + ");";
            String edit = "    public String edit(" + voName + " " + voParam + ");";
            String delete = "    public String delete(" + voName + " " + voParam + ");";
            GenerateCodeUtil.write(serviceFile, getPageList);
            GenerateCodeUtil.write(serviceFile, getAllList);
            GenerateCodeUtil.write(serviceFile, add);
            GenerateCodeUtil.write(serviceFile, edit);
            GenerateCodeUtil.write(serviceFile, delete);
            GenerateCodeUtil.write(serviceFile, classEd);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            GenerateCodeUtil.write(serviceImplFile, "package " + servicePackage + ".impl;");
            GenerateCodeUtil.write(serviceImplFile, "");
            GenerateCodeUtil.write(serviceImplFile, "import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;");
            GenerateCodeUtil.write(serviceImplFile, "import com.baomidou.mybatisplus.core.metadata.IPage;");
            GenerateCodeUtil.write(serviceImplFile, "import com.baomidou.mybatisplus.extension.plugins.pagination.Page;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.base.enums.EStatus;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.base.superI.SuperServiceImpl;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.commons.utils.ResultUtil;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.commons.utils.StringUtils;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.xo.global.MessageConf;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.xo.global.SQLConf;");
            GenerateCodeUtil.write(serviceImplFile, "import com.zrwl.poscloud.xo.global.SysConf;");
            GenerateCodeUtil.write(serviceImplFile, "import org.springframework.beans.BeanUtils;");
            GenerateCodeUtil.write(serviceImplFile, "import org.springframework.beans.factory.annotation.Autowired;");
            GenerateCodeUtil.write(serviceImplFile, "import org.springframework.stereotype.Service;");
            GenerateCodeUtil.write(serviceImplFile, "");


            GenerateCodeUtil.write(serviceImplFile, "import java.util.Date;");
            GenerateCodeUtil.write(serviceImplFile, "import java.util.List;");


            GenerateCodeUtil.write(serviceImplFile, "import " + mapperPackage + "." + entityName + mapperEnd + ";");
            GenerateCodeUtil.write(serviceImplFile, "import " + servicePackage + "." + entityName + serviceEnd + ";");
            GenerateCodeUtil.write(serviceImplFile, "import " + voPackage + "." + voName + ";");
            GenerateCodeUtil.doImport(serviceImplFile, entity);
            String classBg = "/**\n" +
                    " * " + entitySummary + " 服务实现类\n" +
                    " *\n" +
                    " * @author " + author + " AutoGenerate\n" +
                    " * @date " + now() + "\n" +
                    " */\n" +
                    "@Service\n" +
                    "public class " + serviceImplName + " extends SuperServiceImpl<" + entityName + mapperEnd + "," + entityName + "> implements " + entityName + serviceEnd + " {\n";
            String classEd = "}";
            GenerateCodeUtil.write(serviceImplFile, classBg);
            GenerateCodeUtil.write(serviceImplFile, "" +
                    "    @Autowired\n" +
                    "    private " + entityName + serviceEnd + " " + serviceBeanName + ";" +
                    "");

            String getPageList = "" +
                    "    @Override\n" +
                    "    public IPage<" + entityName + "> getPageList(" + voName + " " + voParam + "){\n" +
                    "       QueryWrapper<" + entityName + "> queryWrapper = new QueryWrapper<>();\n" +
                    "       if (StringUtils.isNotEmpty(" + voParam + ".getKeyword()) && !StringUtils.isEmpty(" + voParam + ".getKeyword().trim())) {\n" +
                    "            queryWrapper.like(\"name\", " + voParam + ".getKeyword().trim());\n" +
                    "       }\n" +
                    "       Page<" + entityName + "> page = new Page<>();\n" +
                    "       page.setCurrent(" + voParam + ".getCurrentPage());\n" +
                    "       page.setSize(" + voParam + ".getPageSize());\n" +
                    "       queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);\n" +
                    "       queryWrapper.orderByDesc(SQLConf.CREATE_TIME);\n" +
                    "       IPage<" + entityName + "> pageList = " + serviceBeanName + ".page(page, queryWrapper);\n" +
                    "       List<" + entityName + "> list = pageList.getRecords();\n" +
                    "       pageList.setRecords(list);\n" +
                    "       return pageList;\n" +
                    "}";
            String getAllList = "" +
                    "    @Override\n" +
                    "    public List<" + entityName + "> getAllList(" + voName + " " + voParam + "){\n" +
                    "        QueryWrapper<" + entityName + "> queryWrapper = new QueryWrapper<>();\n" +
                    "        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);\n" +
                    "        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);\n" +
                    "        List<" + entityName + "> list = " + serviceBeanName + ".list(queryWrapper);\n" +
                    "        return list;\n" +
                    "}";
            String add = "" +
                    "    @Override\n" +
                    "    public String add(" + voName + " " + voParam + "){\n" +
                    "        " + entityName + " entity = new " + entityName + "();\n" +
                    "        BeanUtils.copyProperties(" + voParam + ", entity, SysConf.STATUS);\n" +
                    "        entity.insert();\n" +
                    "        "+voParam+".setUid(entity.getUid());\n" +
                    "        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);" +
                    "}";
            String edit = "" +
                    "    @Override\n" +
                    "    public String edit(" + voName + " " + voParam + "){\n" +
                    "        " + entityName + " entity = " + serviceBeanName + ".getById(" + voParam + ".getUid());\n" +
                    "        BeanUtils.copyProperties(" + voParam + ", entity);\n" +
                    "        entity.updateById();\n" +
                    "        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);\n" +
                    "}";
            String delete = "" +
                    "    @Override\n" +
                    "    public String delete(" + voName + " " + voParam + "){\n" +
                    "        " + entityName + " entity = " + serviceBeanName + ".getById(" + voParam + ".getUid());\n" +
                    "        entity.setStatus(EStatus.DISABLED);\n" +
                    "        entity.updateById();\n" +
                    "        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);\n" +
                    "}";
            GenerateCodeUtil.write(serviceImplFile, getPageList);
            GenerateCodeUtil.write(serviceImplFile, getAllList);
            GenerateCodeUtil.write(serviceImplFile, add);
            GenerateCodeUtil.write(serviceImplFile, edit);
            GenerateCodeUtil.write(serviceImplFile, delete);

            GenerateCodeUtil.write(serviceImplFile, classEd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    static void prl(String string) {
        System.out.println(string);
    }

    static String now() {
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        return f.format(now);
    }

    @Test
    public void coverEntity() {
        String entity = "  ";
        do {
            int index = entity.indexOf("_");
            if (index < 0) break;
            String word = entity.substring(index + 1, index + 2);
            String upWord = word.toUpperCase();
            entity = entity.replace("_" + word, upWord);
        } while (true);
        System.out.println(entity);
    }
}
